package com.kaifamiao.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.logging.Logger;

public class SessionLifecycleListener implements HttpSessionListener {

    private Logger logger = Logger.getLogger( this.getClass().getName() );

    // 当一个会话被创建后就会调用该方法
    @Override
    public void sessionCreated( HttpSessionEvent event ) {
        HttpSession session = event.getSession();
        logger.info( "已经创建[ " + session.getId() + " ]会话(" + session.isNew() + ")" );
    }

    // 当一个会话被销毁后就会调用该方法
    @Override
    public void sessionDestroyed( HttpSessionEvent event ) {
        HttpSession session = event.getSession();
        logger.info( "已经销毁[ " + session.getId() + " ]会话" );
    }

}
